<template>
  <div class="box">
    <div class="bg"></div>
    <van-nav-bar
      id="van-bar"
      :title="title"
      fixed
      :border="border"
      left-arrow
      @click-left="onClickLeft"
    >
      <template #left>
        <img
          :style="{ width: widthPx, height: heightPx }"
          src="@/assets/iconPerfectInformation/nav_back@2x.png"
        />
      </template>
    </van-nav-bar>
    <div
      :style="
        'margin-top:' +
        topheight +
        'px;height:calc(100vh - ' +
        topheight +
        'px);width:100%;overflow:auto;'
      "
    >
      <div class="blacklist">
        <div class="list" v-for="(item, index) in list" :key="index">
          <span class="name">{{ item.name }}</span>
          
          <span class="vip" v-if="item.isvip">VIP</span>
           <van-switch v-model="item.istrue" @change="editSetting(index)" size="10px" style="margin: 5px 0;float: right;"/>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {SetSetting, getSetting} from "@/api/setting"

export default {
  data() {
    return {
      border: "",
      widthPx: "28px",
      heightPx: "28px",
      topheight: 0,
      isActive: 0,
      title: "通知设置",
      list: [
        {
          name: "关闭消息推送",
          istrue: false,
          isvip:false
        },
        {
          name: "关注用户上线提醒",
          istrue: false,
          isvip:false
        },{
          name: "关注用户动态提醒",
          istrue: false,
          isvip:false
        },{
          name: "新增粉丝提醒",
          istrue: false,
          isvip:false
        },{
          name: "ta人看过我的提醒",
          istrue: false,
          isvip:false
        },{
          name: "邀请好友提醒",
          istrue: false,
          isvip:false
        }
      ],
    };
  },
  mounted() {
    this.topheight = document.getElementById("van-bar").offsetHeight;
  this.getSetting()
  },

  methods: {
    onClickLeft() {
      this.$router.back();
    },
    getSetting(){
             getSetting(
            ).then((res) => {
              this.list[0].istrue=res.data.chat_notice==1?true:false
              this.list[1].istrue=res.data.follow_notice==1?true:false
              this.list[2].istrue=res.data.dynamic_notice==1?true:false
              this.list[3].istrue=res.data.fans_notice==1?true:false
              this.list[4].istrue=res.data.see_notice==1?true:false
              this.list[5].istrue=res.data.invitation_notice==1?true:false
              console.log(this.list);
      
      })
    },
    editSetting(index){
       let data={}
        if (index==0) {
             data.chat_notice=this.list[0].istrue?1:0
          
        }else if(index==1){
             data.follow_notice=this.list[1].istrue?1:0
         
        }
        else if(index==2){
             data.dynamic_notice=this.list[2].istrue?1:0
          
        }
        else if(index==3){
             data.fans_notice=this.list[3].istrue?1:0
            
        }
        else if(index==4){
             data.see_notice=this.list[4].istrue?1:0
           
        }
        else if(index==6){
             data.invitation_notice=this.list[5].istrue?1:0
            
        }
            // let data={
            //   chat_notice:'',
            //   follow_notice:'',
            //   dynamic_notice:'',
            //   fans_notice:'',
            //   see_notice:'',
            //   invitation_notice:'',
            // }
      console.log(data);
             SetSetting({...data}
            ).then((res) => {
            this.getSetting()
      
      })
    }
  },
};
</script>

<style scoped>
.blacklist {
  width: 345px;
  margin: 0 auto;
}
.headImg {
  width: 40px;
  height: 40px;
}
.list {
  padding: 16px 0;
  border-bottom: #D8D8D8 solid 1px;
}
.list span {
  display: inline-block;
  vertical-align: top;
}
.name{
  margin: 0 7px;
  font-size: 14px;
font-family: PingFangSC, PingFang SC;
font-weight: 600;
color: #1A1A1A;

}

.van-cell {
  background-color: transparent;
}
.van-cell::after {
  border-color: #d8d8d8;
}
.van-cell__value {
  color: #1a1a1a;
  font-weight: 500;
}
</style>
